﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Collections;

namespace Shoozla.DataModel 
{
    public class StatisticsLogger : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        public StatisticsLogger()
        {
            Reset();
        }

        #region properties

        private int _artistFound;
        public int ArtistFound
        {
            get { return _artistFound; }
             set
            {
                if (_artistFound != value)
                {
                    _artistFound = value;
                    OnPropertyChanged("ArtistFound");
                }
            }
        }

        private int _songFound;
        public int SongFound
        {
            get { return _songFound; }
             set
            {
                if (_songFound != value)
                {
                    _songFound = value;
                    OnPropertyChanged("SongFound");
                }
            }
        }

        private int _albumFound;
        public int AlbumFound
        {
            get { return _albumFound; }
             set
            {
                if (_albumFound != value)
                {
                    _albumFound = value;
                    OnPropertyChanged("AlbumFound");
                }
            }
        }

        //globally read files
        private int _totalFiles;
        public int TotalFiles
        {
            get { return _totalFiles; }
            set
            {
                    if (_totalFiles != value)
                    {
                        _totalFiles = value;
                        OnPropertyChanged("TotalFiles");
                    }
            }
        }


        private int _totalSearchedFiles;
        public int TotalSearchedFiles
        {
            get { return _totalSearchedFiles; }
            set
            {
                if (_totalSearchedFiles != value)
                {
                    _totalSearchedFiles = value;
                    OnPropertyChanged("TotalSearchedFiles");
                }
            }
        }

        public int FoundCovers
        {
            get { return AlbumFound+ArtistFound+SongFound; }
        }

        
        private int _fileMatched;
        /// <summary>
        /// number of files that has a cover after the search
        /// </summary>
        public int FileMatched
        {
            get { return _fileMatched; }
            set
            {
                if (_fileMatched != value)
                {
                    _fileMatched = value;
                    OnPropertyChanged("FileMatched");
                }
            }
        }

        public double  SuccessPercentuage
        {
            get { return FileMatched * 100 / TotalSearchedFiles; }
        }

        public double ErrorPercentuage
        {
            get { return 1 - SuccessPercentuage; }
        }

        #endregion

        void OnPropertyChanged(string propname)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new
            PropertyChangedEventArgs(propname));
        }

        public void Reset()
        {
            TotalFiles = 0;
            ArtistFound = 0;
            AlbumFound = 0;
            SongFound = 0;
            TotalSearchedFiles = 0;
        }
    }
}
